#include <windows.h>
#include "State.h"
#include "StateMgr.h"

//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
CStateMgr::CStateMgr()
{
	m_numState = 0;
}



//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
CStateMgr::~CStateMgr()
{
}



//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
void CStateMgr::addState( CState &state )
{
	memcpy(&m_StateList[m_numState], &state, sizeof(state));
	m_numState++;
}



//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
void CStateMgr::delState( DWORD state )
{
	for(int i=0; i < m_numState; ++i)
	{
		if(m_StateList[i].getState() == state)
		{
			int size = ( m_numState - (i+1) ) * sizeof(m_StateList[0]);

			if( size != 0 )
			memcpy( &m_StateList[i], &m_StateList[i+1], size );			
		}
	}
}



//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
DWORD CStateMgr::getCurState()
{
	return m_curState;
}



//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
void CStateMgr::setCurState( DWORD state )
{
	m_curState = state;
}



//-----------------------------------------------------------------------------------------------------------------------
//	Name : 
//	Desc : 
//-----------------------------------------------------------------------------------------------------------------------
void CStateMgr::transitionState( DWORD input )
{
	for(int i=0; i < m_numState; ++i)
	{
		if(m_StateList[i].getState() == m_curState)
		{
			m_curState = m_StateList[i].getTransitionState(input);
			return;
		}
	}
}